import { defineStore } from 'pinia';

export const useOrderStore = defineStore('order', {
	state: () => ({
		orderList: [],
	}),
	actions: {
		addOrder(order) {
			// 检查是否已存在相同 ID 的订单
			const isExist = this.orderList.some((o) => o.id === order.id);
			if (!isExist) {
				this.orderList.unshift(order);
			} else {
				// 可选：提示用户或处理重复逻辑
				console.warn('订单已存在，无法重复添加');
			}
		},

		removeOrder(orderId: string | number) {
			this.orderList = this.orderList.filter((o) => o.id !== orderId);
		},
	},
	persist: true,
});
